package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.common.redis.cache.GuiguCache;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import com.spzx.product.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品sku 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2024-10-26
 */
@Service
public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, ProductSku> implements ProductSkuService {

    @Autowired
    private RedisTemplate redisTemplate;

    @GuiguCache(prefix = "productSku:")
    @Override
    public ProductSku getProductSkuById(Long id) {
        //如果连接Redis出现异常，我们为了保证能查到数据，再查询一次数据库
        ProductSku productSku = baseMapper.selectById(id);
        //设置skuId的值
        productSku.setSkuId(id);
        return productSku;
    }
}
